package com.hot100;

public class Solution34 {
    public int[] searchRange(int[] nums, int target) {
        int i = search(nums, target);
        int j = search(nums, target + 1);
        if (i == nums.length || nums[i] != target) return new int[]{-1, -1};
        return new int[]{i, j - 1};
    }

    public int search(int[] nums, int target) {
        int i = 0;
        int j = nums.length;
        while (i < j) {
            int mid = (i + j) >> 1;
            if (nums[mid] >= target) {
                j = mid;
            } else {
                i = mid + 1;
            }
        }
        return i;
    }
}
